package ui20131001.service
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import model.registry.EnvConst;

	/**
	 * @author : LIMIN
	 * @time : 下午08:20:51
	 * 
	 * @remarks :实时定位
	 */
	public class IndiAtOncePositionCmd
	{
		private static var _timer:Timer;
		private static var _cmd:IndiCurrPositionDataCmd;
		
		
		public function IndiAtOncePositionCmd(cmd:IndiCurrPositionDataCmd)
		{
			_cmd = cmd;
		}
		
		public function execute():void
		{
			if(!_timer)
			{
				_timer = new Timer(EnvConst.REAL_TIME_REFRESH);
				_timer.addEventListener(TimerEvent.TIMER,onAtOnce);
			}
			
			_timer.reset();
			_timer.addEventListener(TimerEvent.TIMER, onAtOnce);
			_timer.start();
			onAtOnce();
		}
		
		private function onAtOnce(e:TimerEvent=null):void
		{
			if(!_cmd)
			{
				stop();
			}
			_cmd.execute();
		}
		
		/** 停止当前位置 */
		public static function stop():void
		{
			if(_timer && _timer.running)
			{
				_timer.stop();
			}
			_cmd = null;
		}
		
	}
}